function [fdata_x, fdata_y, Imax, a, v05, err] = inactivation_fit(x_data, y_data, lam, params, maxiter)
% activation parameter fitting
% try single boltzmann fit  I=Imax/(1+exp(-a*z(V-V0.5)) + I0;
% Fits directly to current


model=22;	%single boltzman without normalization, and has an offset
alpha=(10^-3)*9.648*10^4/(8.3143*(273.16+params(2)));	%1/25mV  =F/RT
% alpha=F_RT(params(2));
FitData(:,1)=x_data';

m=max(y_data);

FitData(:,2)=y_data'; % normalize the data

%parameters: imax     k      V0.5    i0
initpar = lam;
pmask =   [1   1,      1,       1];
lbound =  [-m -20,   -175     0];
ubound =  [2*m 20,    100      m];
order=length(initpar);
beta = params(1);

[c,lam]=curve_fitting(FitData(:,1), FitData(:,2), 'levenberg','cubic', model, order, initpar,...
   pmask, lbound, ubound, alpha, beta, maxiter);

%now plot it
t = FitData(:,1); 
z = FitData(:,2);
err=sum((z-(lam(1)./(1+exp(-lam(2)*alpha*(t-lam(3))))+lam(4))).^2);
fdata_x=min(t):2:max(t);
%calculate a couple more values, cuz it looks better
fdata_y=lam(4) + lam(1)./(1+exp(-lam(2)*alpha*(fdata_x-lam(3))));
Imax=lam(1); a=lam(2); v05=lam(3);



